package com.example.zhaojianxu.signin.securities.view

import android.os.Bundle
import android.util.Log
import android.view.View
import com.example.zhaojianxu.signin.common.constance.ComConstance
import com.example.zhaojianxu.signin.common.http.HttpUtil
import com.example.zhaojianxu.signin.common.util.ToastUtil
import kotlinx.android.synthetic.main.fragment_dialog_number.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

/**
 * create by @zhaojianxu on 2019/3/4
 */
class BuyDialogFragment: NumberDialogFragment(){


    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        dialog_number_text.text = "请输入购买数量"
        dialog_number_btn.text = "购买"
        dialog_number_btn.setOnClickListener {
            buy()
        }
    }

    fun buy(){

        val bid = arguments?.getInt("bid")
        if (bid == null){
            ToastUtil.instance.showToast(this.activity,"服务器出错了～")
            dismiss()
        }
        val number = dialog_number_edit.text.toString().toInt()
        Log.d("TAGGGGG","uid = ${ComConstance.UID}   bid = $bid    number = $number")
        HttpUtil.instance.getSecuritiesApi()?.postBuy(ComConstance.UID,bid!!,number)?.enqueue(object : Callback<String>{
            override fun onFailure(call: Call<String>, t: Throwable) {

            }

            override fun onResponse(call: Call<String>, response: Response<String>) {
                if (response.isSuccessful){
                    dismiss()
                }
            }

        })
    }
}